package com.aviation.air1.mapper;

import com.aviation.air1.entity.AirportAircraftCountVO;
import com.aviation.air1.entity.AviationEntity;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author: dsf
 * @Description:
 * @DateTime: 2025/4/22 17:06
 **/
@Mapper
public interface IAviationDao1 extends BaseMapper<AviationEntity> {

    @Select("select count(distinct source_airport) from interface_data")
    Integer countUniqueIcao();

    @Select("select count(distinct aircraft_type) from interface_data")
    Integer countUniqueCraftType();

    @Select("select avg(cpu_usage_rate) as average_cpu_usage from interface_data")
    Double caclulateCPUOccupancy();

    @Select("select avg(memory_usage_rate) as average_memory_usage from interface_data")
    Double caclulateMemoryOccupancy();

    @Select("select sum(fault_count)/count(*) as failue_rate from interface_data ")
    Double getFailureRate();

    @Select("select count(distinct registration_number) from interface_data")
    Integer countUniqueRegistrationCount();

    @Select("SELECT source_airport AS airport, COUNT(DISTINCT registration_number) AS aircraft_count " +
            "FROM interface_data " +
            "GROUP BY source_airport")
    List<AirportAircraftCountVO> countAircraftByAirport();


}
